package com.hengda.museumonline.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hengda.museumonline.R;
import com.hengda.museumonline.entity.InternationalBean;
import com.hengda.museumonline.ui.NewsContentActivity;

import static com.yolanda.nohttp.NoHttp.getContext;

/**
 * @author：JFWU on 2016/9/26 18:36
 * @E-mail：jeffy12138@126.com
 */
public class InternationalAdapter extends RecyclerView.Adapter<InternationalAdapter.ListHolder> {
    private Context context;
    private InternationalBean.DataBean dataBean;

    public InternationalAdapter(Context context, InternationalBean.DataBean dataBean) {
        this.context = context;
        this.dataBean = dataBean;
    }

    @Override
    public InternationalAdapter.ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.phone_item, parent, false);
        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(InternationalAdapter.ListHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return dataBean.getPhotos().size();
    }

    class ListHolder extends RecyclerView.ViewHolder {
        ImageView iv_image;


        public ListHolder(View itemView) {
            super(itemView);
            iv_image = (ImageView) itemView.findViewById(R.id.image);
        }

        public void setData(int position) {
            Glide.with(getContext()).load(dataBean.getPhotos().get(position)).into(iv_image);
            iv_image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Bundle bundle = new Bundle();
                    bundle.putString("object_id", dataBean.getObject_id());
                    Intent intent = new Intent(context, NewsContentActivity.class);
                    intent.putExtras(bundle);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                }
            });
        }


    }
}
